# 进入sqoop-link项目
BASE_PATH=$(cd "$(dirname "$0")" || exit ; pwd)
cd "${BASE_PATH}" || exit
echo "Sqoop-Link ==> Go to ${BASE_PATH}"

# 打包
echo "Sqoop-Link ==> Start build"
mvn clean package -Dmaven.test.skip -pl link-common,link-plugin || exit
echo "Sqoop-Link ==> Build success"

# 创建link文件夹
LINK_BUILD_DIR="${BASE_PATH}"/build
if [ -d "${LINK_BUILD_DIR}" ]; then
    rm -rf "${LINK_BUILD_DIR}"
    echo "Sqoop-Link ==> Delete link success"
fi
mkdir -p "${LINK_BUILD_DIR}"
echo "Sqoop-Link ==> Create link success"

# 创建bin文件夹
mkdir -p "${LINK_BUILD_DIR}"/bin
cp "${BASE_PATH}"/link-plugin/bin/* "${LINK_BUILD_DIR}"/bin
chmod a+x "${LINK_BUILD_DIR}"/bin/*
echo "Sqoop-Link ==> Create bin dir success"

# 创建conf文件夹
mkdir -p "${LINK_BUILD_DIR}"/conf
cp "${BASE_PATH}"/link-plugin/conf/* "${LINK_BUILD_DIR}"/conf
echo "Sqoop-Link ==> Create conf dir success"

# 创建log文件夹
mkdir -p "${LINK_BUILD_DIR}"/log
echo "Sqoop-Link ==> Create log dir success"

# 创建lib文件夹
mkdir -p "${LINK_BUILD_DIR}"/lib
cp "${BASE_PATH}"/link-plugin/target/link-plugin.jar "${LINK_BUILD_DIR}"/lib/link-plugin.jar
echo "Sqoop-Link ==> Create lib dir success"

# 创建plugins文件夹
mkdir -p "${LINK_BUILD_DIR}"/plugins
echo "Sqoop-Link ==> Create plugins dir success"

# 创建tmp文件夹
mkdir -p "${LINK_BUILD_DIR}"/tmp
echo "Sqoop-Link ==> Create tmp dir success"
